<!--集团动态-->
<template>
  <el-card class="mt15 mb15">
    <div class="search-filter">
      <el-row :gutter="20">
        <el-col :span="6">
          <sitem label="日志内容：">
            <el-input
              slot="item"
              v-model="listQuery.keyWord"
              placeholder="请输入"
              clearable
              @input="handleFilter"
            />
          </sitem>
        </el-col>
        <el-col :span="6">
<!--          <sitem label="字典编码："> </sitem>-->


                <el-date-picker
                  v-model="createTime"
                  type="monthrange"
                  align="right"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始月份"
                  end-placeholder="结束月份"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  @change="handleFilter"
                  :picker-options="pickerOptions">
                </el-date-picker>


        </el-col>
        <el-col :span="6">
          <sitem label="">
            <el-button
              slot="item"
              v-waves
              class="el-icon-search"
              type="primary"
              style="width: 80px"
              @click="handleFilter"
            >
              搜索
            </el-button>
          </sitem>
        </el-col>
      </el-row>
    </div>
<!--    <div class="mb15">-->
<!--      <el-button type="primary" icon="el-icon-document-add" @click="editShow('新增',null)">新增</el-button>-->
<!--    </div>-->
    <el-table
      :data="list"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
    >


      <!-- 缩略图 -->
      <el-table-column align="left" prop="logContent" label="日志内容"></el-table-column>
      <el-table-column align="left" prop="ip" label="IP"></el-table-column>
      <el-table-column align="center" prop="costTime" label="耗时（毫秒）"></el-table-column>
      <el-table-column align="left" prop="userid" label="操作人ID"></el-table-column>
      <el-table-column align="center" label="日志类型" prop="logType_dictText"></el-table-column>


      <el-table-column align="center" prop="operateType_dictText" label="操作类型">

      </el-table-column>
      <el-table-column align="center" label="创建时间" prop="createTime"></el-table-column>

      <el-table-column label="操作" width="200px" fixed="right" align="center">
        <template slot-scope="{row,$index}">
          <el-button type="text" @click="editShow('查看',row)">查看</el-button>
          <!--                    <el-button type="text" @click="delItem(row,$index)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" next-text="下一页" layout="prev, pager, next, jumper"
                :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="getList"/>
    <editDrawer ref="editDrawer" @refresh="refresh"/>
  </el-card>
</template>
<script>
  import {sys_log_list} from '@/api/sys_log'
  import waves from '@/directive/waves' // waves directive
  import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  import editDrawer from './components/editDrawer'
  import sitem from "@/components/searchItem/index";

  export default {
    name: 'ComplexTable',
    components: {
      Pagination,
      editDrawer,sitem

    },
    directives: {
      waves
    },
    data() {
      return {
        pickerOptions: {
          shortcuts: [{
            text: '本月',
            onClick(picker) {
              picker.$emit('pick', [new Date(), new Date()]);
            }
          }, {
            text: '今年至今',
            onClick(picker) {
              const end = new Date();
              const start = new Date(new Date().getFullYear(), 0);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近六个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setMonth(start.getMonth() - 6);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        createTime: '',

        list: [], // 内容列表
        total: 0, // 总页数
        listLoading: true,
        // 查询参数
        listQuery: {
          // logType: 2,
          column: 'createTime',
          order: 'desc',
          field: 'id,,,logContent,userid,username,ip,costTime,logType_dictText,operateType_dictText,createTime',
          pageNo: 1,
          pageSize: 10

        }
      }
    },
    created() {
      this.getList()
    },
    methods: {
      // 外部分页 -- 搜索
      handleFilter() {
        this.listQuery.pageNo = 1
        this.getList(this.listQuery)

      },
      // 打开编辑弹窗
      editShow(title, rowData) { // rowData 暂未使用
        this.$refs.editDrawer.show(title, rowData)
      },
      refresh() {
        this.getList()
      },
      // 分页数据
      getList() {

      console.log("日期擦 "+this.createTime)
        this.listQuery.createTime_begin=this.createTime[0];
          this.listQuery.createTime_end=this.createTime[1];

        this.listLoading = true
        sys_log_list(this.listQuery).then(response => {
          let list = response.result.records;
          this.list = list
          this.total = response.result.total
          this.listLoading = false
        })
      },
      // 删除
      delItem(e, index) {
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          let p = {
            params: {	// 请求参数拼接在url上
              id: e.id
            }
          };
          menu_delete(p).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.refresh()
          })
          // this.list.splice(index, 1)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
    }
  }
</script>
<style lang="scss" scoped>
</style>
